

module.exports = class poster_dao extends require('../sql/parking_sql'){

    /**
     * 获取车位信息
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async getParkData(req,resp){
        let query = req.query;
        let parkname = query.parkname;
        let parkpay = query.parkpay;
        let parktype = query.parktype;
        let parkstatus = query.parkstatus;
        let currPage = query.currPage;
        let pageNum = query.pageNum;

        let data = await this.getParkDataSql(parkname,parkpay,parktype,parkstatus,currPage,pageNum);
        let total = await this.getParkDataTotal(parkname,parkpay,parktype,parkstatus);
        resp.send({data,total:total[0].count})
    }


    /**
     * 添加车位
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async addParkData(req,resp){
        let body = req.body;
        let parkname = body.parkname;
        let parkpay = body.parkpay;
        let parktype = body.parktype;
        let parkstatus = body.parkstatus;
        let results = await this.addParkDataSql(parkname,parkpay,parktype,parkstatus)
        resp.send(results)
    }


    /**
     * 删除车位
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async delParkData(req,resp){
        let id = req.query.id
        let results = await this.delParkDataSql(id)
        resp.send(results)
    }


    /**
     * 编辑车位
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async editParkData(req,resp){
        let body = req.body;
        let u_id = body.u_id;
        let parkname = body.parkname;
        let parkpay = body.parkpay;
        let parktype = body.parktype;
        let parkstatus = body.parkstatus;
        let results = await this.editParkDataSql(u_id,parkname,parkpay,parktype,parkstatus)
        resp.send(results)

    }


    /**
     * 更新车位状态
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async updateParkData(req,resp){
        let body = req.body;
        let id = body.id;
        let parktype = body.parktype;
        let parkstatus = body.parkstatus;
        let results = await this.updateParkDataSql(id,parktype,parkstatus);
        resp.send(results)
    }


    /**
     * 获取车位订单
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async getParkOrder(req,resp){
        let query = req.query;
        let parkname = query.parkname;
        let orderpay = query.orderpay;
        let orderstatus = query.orderstatus;
        let pageNum = query.pageNum;
        let currPage = query.currPage;

        let data = await this.getParkOrderSql(parkname,orderpay,orderstatus,currPage,pageNum);
        let total = await this.getParkOrderTotal(parkname,orderpay,orderstatus);
        resp.send({data,total:total[0].count})
    }


    /**
     * 编辑车位订单
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async editParkOrder(req,resp){
        let body = req.body;
        let u_id = body.u_id;
        let startdate = body.startdate;
        let enddate = body.enddate;
        let orderpay = body.orderpay;
        let orderstatus = body.orderstatus;
        let note = body.note;
        let results = await this.editParkOrderSql(u_id,startdate,enddate,orderpay,orderstatus,note)
        resp.send(results)

    }


    /**
     * 用户车位缴费
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async payParkOrder(req,resp){
        let body = req.body;
        let u_id = body.u_id;
        let orderstatus = body.orderstatus;
        let reply = body.reply;
        let results = await this.payParkOrderSql(u_id,orderstatus,reply)
        resp.send(results)

    }
    
    
};